from sklearn import datasets
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from pylab import mpl
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler
from sklearn.preprocessing import StandardScaler

# 设置中文字体
mpl.rcParams['font.sans-serif'] = ['SimHei']
# 设置正常显示符号
mpl.rcParams['axes.unicode_minus'] = False
# 解决中文乱码
plt.rcParams['font.sans-serif'] = ['SimHei']

# 获取数据
iris = datasets.load_iris()  # 获取小数据集
iris_d = pd.DataFrame(data=iris.data, columns=['Sepal_Length', 'Sepal_Width', 'Petal_Length', 'Petal_Width'])


news = datasets.fetch_20newsgroups(data_home=None, subset='train')  # 获取大数据集，subset：'train'或者'test'，'all'，可选，选择要加载的数据集

# print("鸢尾花数据集的返回值：\n", iris)
# # 返回值是一个继承自字典的Bench
# print("鸢尾花的特征值:\n", iris.data)
# print("鸢尾花的目标值：\n", iris.target)
# print("鸢尾花特征的名字：\n", iris.feature_names)
# print("鸢尾花目标值的名字：\n", iris.target_names)
# print("鸢尾花的描述：\n", iris.DESCR)

news = datasets.fetch_20newsgroups(data_home=None, subset='train')  # 获取大数据集，subset：'train'或者'test'，'all'，可选，选择要加载的数据集

print("鸢尾花数据集的返回值：\n", iris)
# 返回值是一个继承自字典的Bench
print("鸢尾花的特征值:\n", iris.data)
print("鸢尾花的目标值：\n", iris.target)
print("鸢尾花特征的名字：\n", iris.feature_names)
print("鸢尾花目标值的名字：\n", iris.target_names)
print("鸢尾花的描述：\n", iris.DESCR)

# 数据集可视化
# iris_d = pd.DataFrame(data=iris.data, columns=['Sepal_Length', 'Sepal_Width', 'Petal_Length', 'Petal_Width'])
# iris_d['target'] = iris.target
# print(iris_d.head())
#
#
# def plot_iris(col1, col2, data):
#
#     # x, y,分别代表横纵坐标的列名
#     # data 是关联到数据集
#     # hue 是目标值
#     # fit_reg  是否进行线性拟合
#     sns.lmplot(data=data, x=col1, y=col2, hue='target', fit_reg=False)
#     plt.xlabel(col1)
#     plt.ylabel(col2)
#     plt.title("鸢尾花种类分布图")
#     plt.show()
#
# if __name__ == '__main__':
#     plot_iris(data=iris_d,col1='Sepal_Length',col2='Petal_Length')


# 训练集与测试集的划分
# 训练集的特征值x_train 测试集的特征值x_test 训练集的目标值y_train 测试集的目标值y_test
# x_train, x_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size=0.2, random_state=2)
# print(x_train.shape[0])
# print(x_test.shape[0])
# print(x_test)
# # 随机数种子
# x_train1, x_test1, y_train1, y_test1 = train_test_split(iris.data, iris.target, random_state=6)
# x_train2, x_test2, y_train2, y_test2 = train_test_split(iris.data, iris.target, random_state=6)


# 特征工程----归一化和标准化
# # 归一化
# def minmax_demo():
#     # 实例化一个转换器类
#     transfer = MinMaxScaler(feature_range=(2, 3))
#     minmax_data = transfer.fit_transform(iris_d[['Sepal_Length', 'Petal_Length']])
#     print("最小值最大值归一化处理的结果：\n", minmax_data)
#
#
# 标准化
# def standard_demo():
#     # 实例化一个转换器类
#     transfer = StandardScaler()
#     standa_data = transfer.fit_transform(iris_d[['Sepal_Length', 'Petal_Length']])
#     print("标准化处理的结果：\n", standa_data)
#     print("每一列特征的平均值：\n", transfer.mean_)
#     print("每一列特征的方差：\n", transfer.var_)

#
#
# minmax_demo()
# standard_demo()
